package org.smr.ministore.micro;

import java.util.List;

import org.blade.dao.base.BaseMapper;
import org.blade.utils.IdGenUtils;
import org.smr.ministore.dao.GoodsImgMapper;
import org.smr.ministore.entities.Goods;
import org.smr.ministore.entities.GoodsImg;
import org.smr.ministore.service.GoodsImgService;
import org.blade.service.base.AbstractService;

import org.blade.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class GoodsImgMicroService extends AbstractService<Long,GoodsImg> implements GoodsImgService {

	@Autowired
	private GoodsImgMapper mapper;

	@Autowired
    public GoodsImgMicroService(GoodsImgMapper mapper) {
        super(mapper);
    }

    @ResponseBody
	@RequestMapping(method = RequestMethod.POST, value = "/GoodsImg/batchSave")
	public int batchSave(@RequestBody List<GoodsImg> entities) {
        this.batchSaveAttatch(entities);
    	return mapper.batchInsert(entities);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/GoodsImg/batchModify")
    public int batchModify(List<GoodsImg> entities) {
        this.batchModifyAttatch(entities);
        return mapper.batchUpdate(entities);
    }


    @ResponseBody
    @RequestMapping(method = RequestMethod.PUT, value = "/GoodsImg/save")
    public int save(@RequestBody GoodsImg entity) {
        this.saveAttatch(entity);
    	return mapper.insert(entity);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.PATCH, value = "/GoodsImg/updateById")
    public int updateById(@RequestBody GoodsImg id) {
        this.modifyAttach(id);
   	 	return mapper.updateById(id);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/GoodsImg/queryById/{id}")
    public GoodsImg queryById( @PathVariable("id")Long id ) {
    	return (GoodsImg) mapper.selectById(id);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.DELETE, value = "/GoodsImg/deleteById/{id}")
    public int deleteById( @PathVariable("id")Long id ) {
        return mapper.deleteById(id);
    }

    @Override
    public int deleteByIdLogical(Long id) {
        return 0;
    }

    @ResponseBody
    @RequestMapping( method = RequestMethod.POST, value = "/GoodsImg/paginate/{pageSize}/{pageNum}")
    public Pager<GoodsImg> paginate( GoodsImg entity, @PathVariable("pageSize")Long pageSize,  @PathVariable("pageNum")Long pageNum ) {
        Pager<GoodsImg> pager = new Pager(pageSize, pageNum);
        List<GoodsImg> list = this.mapper.pagination( entity, pager );
        pager.setEntities(list);
        return pager;
    }


    @ResponseBody
    @RequestMapping( method = RequestMethod.POST, value = "/GoodsImg/getGoodsImgByGoods/{goodsId}")
    public List<GoodsImg> getGoodsImgByGoods(@PathVariable("goodsId")Long goodsId) {
        return this.mapper.getGoodsImgByGoods(goodsId);
    }

    @Override
    public Long getId() {
        return IdGenUtils.getNextLongId();
    }
}
